package logic

import (
	"context"
	"fmt"
	"house/cache"
	"math/rand"
	"time"

	"house/house"
	"house/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SendSmsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLogic {
	return &SendSmsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 短信验证码
func (l *SendSmsLogic) SendSms(in *house.SendSmsReq) (*house.SendSmsResp, error) {
	// todo: 短信验证码
	code := rand.Intn(9000) + 1000
	//sms, err := pkg.SendSms(in.Account, strconv.Itoa(code))
	//if err != nil {
	//	return nil, err
	//}
	//if *sms.Body.Code != "OK" {
	//	return nil, errors.New(*sms.Body.Message)
	//}

	cache.Rdb.Set(cache.Ctx, "sendSms"+in.Account+in.Source, code, time.Minute*5)
	fmt.Println(0)
	return &house.SendSmsResp{}, nil
}
